// if (value == '仓位') {
//     position(value)
// } else if (value == '历史仓位') {
//     historicalPosition(value)
// } else if (value == '当前委托') {
//     currentCommission(value)
// } else if (value == '历史委托') {
//     historicalCommission(value)
// } else if (value == '成交记录') {
//     transactionRecord(value)
// } else if (value == '资金流水') {
//     capitalFlow(value)
// } else if (value == '交易机器人') {
//     tradingRobot(value)
// }

// 交易机器人
export const tradingPerRobotCol = [
    {
        title: '机器人名称',
        dataIndex: 'name',
        key: 'name',
    }, {
        title: '创建时间',
        dataIndex: 'createTime',
        key: 'createTime',
    }, {
        title: '交易对',
        dataIndex: 'tradingPairs',
        key: 'tradingPairs',
    }, {
        title: '投资额',
        dataIndex: 'investmentAmount',
        key: 'investmentAmount',
    }, {
        title: '总收益',
        dataIndex: 'totalRevenue',
        key: 'totalRevenue',
    }, {
        title: '网络收益',
        dataIndex: 'networkRevenue',
        key: 'networkRevenue',
    }, {
        title: '浮动盈亏',
        dataIndex: 'floatingPL',
        key: 'floatingPL',
    }, {
        title: '年化收益率',
        dataIndex: 'annualizedReturn',
        key: 'annualizedReturn',
    }, {
        title: '运行时长',
        dataIndex: 'runningTime',
        key: 'runningTime',
    }, {
        title: '交易次数',
        dataIndex: 'transacNumber',
        key: 'transacNumber',
    }, {
        title: '操作',
        dataIndex: 'action',
        key: 'action',
    }
]

// 资金流水
export const capitalFloCol = [
    {
        title: '时间',
        dataIndex: 'time',
        key: 'time',
    }, {
        title: '金额',
        dataIndex: 'amountMoney',
        key: 'amountMoney',
    }, {
        title: '账户余额',
        dataIndex: 'accountBalance',
        key: 'accountBalance',
    }, {
        title: '操作类型',
        dataIndex: 'operationType',
        key: 'operationType',
    }, {
        title: '合约',
        dataIndex: 'contract',
        key: 'contract',
    }, {
        title: '备注',
        dataIndex: 'remark',
        key: 'remark',
    }
]

import { language } from "@/content-scripts/locales"
// 成交记录
export const transnRecordCol = [

    {
        title: language.contract,
        dataIndex: 'market',
        key: 'market',
        customRender: ({ text, record }) => marketRender(text, record)
    }, {
        title: language.fillPrice,
        dataIndex: 'averagePrice',
        key: 'averagePrice',
        customRender: ({ text }) => priceRender(text)
    }, {
        title: language.currentPrice,
        dataIndex: 'lastPrice',
        key: 'lastPrice',
        customRender: ({ text }) => priceRender(text)
    }, {
        title: language.filledQty,
        dataIndex: 'tradingVolumn',
        key: 'tradingVolumn',
        customRender: ({ text }) => tradingVolumnRender(text)
    }, {
        title: language.tradedAt,
        dataIndex: 'createTime',
        key: 'createTime',
        customRender: ({ text }) => formatTimestamp(text)
    }
]

const marketRender = (text, record) => {
    if (language.lang == 'zh') {
        if (record.side == 'buy') {
            return <span style="color: red;">{text}</span>
        } else {
            return <span style="color: green;">{text}</span>
        }
    } else {
        if (record.side == 'buy') {
            return <span style="color: green;">{text}</span>
        } else {
            return <span style="color: red;">{text}</span>
        }
    }
}

const formatTimestamp = (timestamp) => {
    const date = new Date(timestamp * 1000) // 注意时间戳是秒级需乘以1000
    return `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')} ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}:${date.getSeconds().toString().padStart(2, '0')}`
}

const priceRender = (value) => {
    return `${Number(value).toFixed(3)}`
}

const tradingVolumnRender = (value) => {
    return `${Math.abs(Number(value))}UNI`
}

// 历史委托
export const historyCommission = [
    {
        title: '合约',
        dataIndex: 'contract',
        key: 'contract',
    }, {
        title: '创建时间',
        dataIndex: 'createTime',
        key: 'createTime',
    }, {
        title: '结束时间',
        dataIndex: 'endTime',
        key: 'endTime',
    }, {
        title: '方向',
        dataIndex: 'direction',
        key: 'direction',
    }, {
        title: '成交均价|委托价',
        dataIndex: 'averageTransactionPrice',
        key: 'averageTransactionPrice',
    }, {
        title: '已成交|委托数量',
        dataIndex: 'commissionNum',
        key: 'commissionNum',
    }, {
        title: '平仓收益|收益率',
        dataIndex: 'yieldRate',
        key: 'yieldRate',
    }, {
        title: '生效方式',
        dataIndex: 'effectiveMethod',
        key: 'effectiveMethod',
    }, {
        title: '冰山委托',
        dataIndex: 'icebergComm',
        key: 'icebergComm',
    }, {
        title: '只减仓',
        dataIndex: 'onlyReducingInventory',
        key: 'onlyReducingInventory',
    }, {
        title: '止盈/止损',
        dataIndex: 'profitAndLoss',
        key: 'profitAndLoss',
    }, {
        title: '订单状态',
        dataIndex: 'orderStatus',
        key: 'orderStatus',
    }, {
        title: '来源',
        dataIndex: 'source',
        key: 'source',
    }, {
        title: '委托ID',
        dataIndex: 'commissionId',
        key: 'commissionId',
    }
]

// 当前委托
export const currentComCol = [
    {
        title: '合约',
        dataIndex: 'contract',
        key: 'contract',
    }, {
        title: '创建时间',
        dataIndex: 'createTime',
        key: 'createTime',
    }, {
        title: '方向',
        dataIndex: 'direction',
        key: 'direction',
    }, {
        title: '价格',
        dataIndex: 'price',
        key: 'price',
    }, {
        title: '数量',
        dataIndex: 'number',
        key: 'number',
    }, {
        title: '剩余',
        dataIndex: 'remaining',
        key: 'remaining',
    }, {
        title: '成交均价',
        dataIndex: 'averageTransactionPrice',
        key: 'averageTransactionPrice',
    }, {
        title: '来源',
        dataIndex: 'source',
        key: 'source',
    }, {
        title: '生效方式',
        dataIndex: 'effectiveMethod',
        key: 'effectiveMethod',
    }, {
        title: '冰山委托',
        dataIndex: 'icebergComm',
        key: 'icebergComm',
    }, {
        title: '只减仓',
        dataIndex: 'onlyReducingInventory',
        key: 'onlyReducingInventory',
    }, {
        title: '委托ID',
        dataIndex: 'commissionId',
        key: 'commissionId',
    }, {
        title: '止盈/止损',
        dataIndex: 'profitAndLoss',
        key: 'profitAndLoss',
    }, {
        title: '操作',
        dataIndex: 'action',
        key: 'action',
    },
]

// 历史仓位
export const historyPosCol = [
    {
        title: '合约',
        dataIndex: 'contract',
        key: 'contract',
    }, {
        title: '方向',
        dataIndex: 'direction',
        key: 'direction',
    }, {
        title: '状态',
        dataIndex: 'status',
        key: 'status',
    }, {
        title: '开仓时间',
        dataIndex: 'openTime',
        key: 'openTime',
    }, {
        title: '开仓均价',
        dataIndex: 'averageOpeningPrice',
        key: 'averageOpeningPrice',
    }, {
        title: '平仓均价',
        dataIndex: 'averageClosingPrice',
        key: 'averageClosingPrice',
    }, {
        title: '累计平仓量',
        dataIndex: 'accumulatedVolume',
        key: 'accumulatedVolume',
    }, {
        title: '最大持仓量',
        dataIndex: 'maxPosition',
        key: 'maxPosition',
    }, {
        title: '以实现收益/收益率',
        dataIndex: 'yieldRate',
        key: 'yieldRate',
    }, {
        title: '全部平仓时间',
        dataIndex: 'fullClosingTime',
        key: 'fullClosingTime',
    }, {
        title: '操作',
        dataIndex: 'action',
        key: 'action',
    }
]
// 仓位
export const positionCol = [
    {
        title: '合约',
        dataIndex: 'contract',
        key: 'contract',
    }, {
        title: '数量',
        dataIndex: 'number',
        key: 'number',
    }, {
        title: '开仓均价',
        dataIndex: 'averageOpeningPrice',
        key: 'averageOpeningPrice',
    }, {
        title: '标记价格',
        dataIndex: 'tagPrice',
        key: 'tagPrice',
    }, {
        title: '预估强平价',
        dataIndex: 'estimatedPrice',
        key: 'estimatedPrice',
    }, {
        title: '盈亏平衡价',
        dataIndex: 'breakevenPrice',
        key: 'breakevenPrice',
    }, {
        title: '保证金',
        dataIndex: 'bond',
        key: 'bond',
    }, {
        title: '保证金率',
        dataIndex: 'marginRatio',
        key: 'marginRatio',
    }, {
        title: '未实现盈亏（收益率）',
        dataIndex: 'yieldRate',
        key: 'yieldRate',
    }, {
        title: '已实现盈亏',
        dataIndex: 'realizedProfit',
        key: 'realizedProfit',
    }, {
        title: '仓位止盈/止损',
        dataIndex: 'positionProfitLoss',
        key: 'positionProfitLoss'
    }, {
        title: '部分仓位止盈/止损',
        dataIndex: 'partPositionProfitLoss',
        key: 'partPositionProfitLoss'
    }, {
        title: '追踪止盈',
        dataIndex: 'trackingProfits',
        key: 'trackingProfits'
    }, {
        title: '自动减仓',
        dataIndex: 'autoReducInventory',
        key: 'autoReducInventory'
    }, {
        title: '自动减仓',
        dataIndex: 'autoReducInventory',
        key: 'autoReducInventory'
    }, {
        title: '反手',
        dataIndex: 'backhand',
        key: 'backhand'
    }, {
        title: '减仓/平仓',
        dataIndex: 'reducePositions',
        key: 'reducePositions'
    }
]
export const orderCol = [
    {
        title: '下单日期',
        dataIndex: 'contract',
        key: 'contract',
    }, {
        title: '账号类型',
        dataIndex: 'number',
        key: 'number',
    }, {
        title: '方向',
        dataIndex: 'averageOpeningPrice',
        key: 'averageOpeningPrice',
    }, {
        title: '交易对',
        dataIndex: 'tagPrice',
        key: 'tagPrice',
    }, {
        title: '委托价',
        dataIndex: 'estimatedPrice',
        key: 'estimatedPrice',
    }, {
        title: '成交均价',
        dataIndex: 'breakevenPrice',
        key: 'breakevenPrice',
    }, {
        title: '挂单量',
        dataIndex: 'bond',
        key: 'bond',
    }, {
        title: '挂单金额',
        dataIndex: 'marginRatio',
        key: 'marginRatio',
    }, {
        title: '成交量',
        dataIndex: 'yieldRate',
        key: 'yieldRate',
    }, {
        title: '成交金额',
        dataIndex: 'realizedProfit',
        key: 'realizedProfit',
    }, {
        title: '操作',
        dataIndex: 'action',
        key: 'action'
    }
]
export const historyCol = [
    {
        title: '下单日期',
        dataIndex: 'contract',
        key: 'contract',
    }, {
        title: '账户类型',
        dataIndex: 'number',
        key: 'number',
    }, {
        title: '方向',
        dataIndex: 'averageOpeningPrice',
        key: 'averageOpeningPrice',
    }, {
        title: '交易对',
        dataIndex: 'tagPrice',
        key: 'tagPrice',
    }, {
        title: '委托价',
        dataIndex: 'estimatedPrice',
        key: 'estimatedPrice',
    }, {
        title: '成交均价',
        dataIndex: 'breakevenPrice',
        key: 'breakevenPrice',
    }, {
        title: '挂单量',
        dataIndex: 'bond',
        key: 'bond',
    }, {
        title: '挂单金额',
        dataIndex: 'marginRatio',
        key: 'marginRatio',
    }, {
        title: '成交量',
        dataIndex: 'yieldRate',
        key: 'yieldRate',
    }, {
        title: '成交金额',
        dataIndex: 'realizedProfit',
        key: 'realizedProfit',
    },
    {
        title: '成交日期',
        dataIndex: 'realizedProfit',
        key: 'realizedProfit',
    }, {
        title: '状态',
        dataIndex: 'action',
        key: 'action'
    }
]
export const recordCol = [
    {
        title: '操作单号',
        dataIndex: 'contract',
        key: 'contract',
    }, {
        title: '日期',
        dataIndex: 'number',
        key: 'number',
    }, {
        title: '交易类型',
        dataIndex: 'averageOpeningPrice',
        key: 'averageOpeningPrice',
    }, {
        title: '角色',
        dataIndex: 'tagPrice',
        key: 'tagPrice',
    }, {
        title: '交易对',
        dataIndex: 'estimatedPrice',
        key: 'estimatedPrice',
    }, {
        title: '成交均价',
        dataIndex: 'breakevenPrice',
        key: 'breakevenPrice',
    }, {
        title: '成交量',
        dataIndex: 'bond',
        key: 'bond',
    }, {
        title: '总额',
        dataIndex: 'marginRatio',
        key: 'marginRatio',
    }, {
        title: '手续费',
        dataIndex: 'yieldRate',
        key: 'yieldRate',
    }
]